package demo1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

class Person {

}

class Student extends Person {

}

public class Test1 {
    public static void main(String[] args) {


    }
    //杨辉三角
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        list.add(1);
        ret.add(list);

        for (int i = 1; i < numRows; i++) {
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);

            //处理中间的数字
            List<Integer> preRow = ret.get(i-1);
            for (int j = 1; j < i; j++) {
                int val = preRow.get(j) + preRow.get(j-1);
                curRow.add(val);
            }
            //最后一个数字1
            curRow.add(1);
            ret.add(curRow);
        }
        return ret;
    }

    public static void main4(String[] args) {
        //CVTE面试题：删除第一个字符串中在第二个字符串中出现的字符
        func("hello future","world");
    }
    public static void func(String str1, String str2) {
        List<Character> ret = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch+"")) {
                ret.add(ch);
            }
        }
        //System.out.println(ret);
        for (int i = 0; i < ret.size(); i++) {
            System.out.print(ret.get(i));
        }
        System.out.println();
    }

    public static void main3(String[] args) {
        //遍历arrayList数组
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("abc");
        arrayList.add("yangxuejiao");
        arrayList.add("yangmeimei");
        //1.
        System.out.println(arrayList);
        //2.
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+ " ");
        }
        System.out.println();
        //3.
        for (String str : arrayList) {
            System.out.print(str);
        }
        System.out.println();
        //4.使用迭代器打印
        Iterator<String> it = arrayList.iterator();
        //此时it是指向it首元素的前一个下标位置的，it.hasNext是打印it下一个位置
        //如果有下一个就打印下一个（先走再打印，取走完之后的值）
        while(it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();


        Iterator<String> it2 = arrayList.listIterator();
        while(it2.hasNext()) {
            System.out.print(it2.next()+" ");
        }
        System.out.println();

        //从指定下标位置开始打印
        Iterator<String> it3 = arrayList.listIterator(1);
        while(it3.hasNext()) {
            System.out.print(it3.next()+" ");
        }
        System.out.println();
    }

    public static void main2(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("abc");
        arrayList.add("yangxuejiao");
        arrayList.add("yangmeimei");
        List<String> ret = arrayList.subList(0,3);
        //对指定下标进行修改
        //这里ret的修改会把上面arrayList的0下标的值一起修改了，因为是两个引用指向了同一块空间
        ret.set(0,"yangxiaoxi");
        System.out.println(ret);
    }


    public static void main1(String[] args) {
        //ArrayList扩容是按照1.5倍机制来扩容的，如果ArrayList的size刚开始为0，则首次会扩容10个元素大小的空间
        ArrayList<String> arrayList = new ArrayList<>();
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        List<String> list = new ArrayList<>();
        List<String> list1 = new ArrayList<>(15);
        List<String> list2 = new ArrayList<>(arrayList);
        //报错，因为类型不一样
        //List<String> list3 = new ArrayList<>(arrayList1);
        arrayList.add("abc");
        arrayList.add("def");

        list.add("hello");
        //将所有元素放到list中
        list.addAll(arrayList);
        //删除指定下标的对象
        String ret = list.remove(1);
        //删除指定的对象
        boolean ret1 = list.remove("hello");
        //清空
        list.clear();
        System.out.println("=========");
    }
}
